package org.meetunexpectedly.authority.verify;

import org.meetunexpectedly.util.JwtUtils;
import org.meetunexpectedly.authority.AuthorityUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: post请求授权校验
 * @Author: pupil
 * @Date: 2024/09/03 下午 6:58
 */
@Component(value = "postMappingAuthorityVerify")
public class UnifyAuthorityVerify extends DefaultAuthorityVerify{

    @Override
    public Boolean authorityVerify(HttpServletRequest request, String[] permissions) {

        Long userId = JwtUtils.getUserId(request);
        for (String permission : permissions) {
            if (!AuthorityUtils.verify(userId,permission)) {
                return false;
            }
        }
        return true;
    }
}
